<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li,
        a {
            list-style: none;
            text-decoration: none;
            color: #333;
            font-size: 14px;
        }

        .box {
            width: 200px;
            margin: 100px auto;
        }

        .result-list {
            width: 164px;
            border: 1px solid orange;
            border-top: none;
            display: none;
            position: relative;
        }

        input {
            height: 50px;
        }

        .search {
            border: 1px solid orange;
            outline: none;
        }

        .result-list li {
            height: 30px;
            line-height: 30px;
            padding-left: 10px;
        }

        .result-list li:hover {
            background-color: beige;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="search" placeholder="小米笔记本">
        <ul class="result-list">
            <li><a href="#">全部商品</a></li>
            <li><a href="#">小米SU7</a></li>
            <li><a href="#">小米SU7</a></li>
            <li><a href="#">小米SU7</a></li>
            <li><a href="#">小米SU7</a></li>
            <li><a href="#">小米SU7</a></li>
            <li><a href="#">小米SU7</a></li>
        </ul>
    </div>

    <script>
        const input = document.querySelector('[type=search]')
        const ul = document.querySelector('.result-list')
        // 监听事件 焦点  focus获得焦点
        input.addEventListener('focus', function () {
            ul.style.display = "block"
            input.classList.add('search')
        })
        //blur 失去焦点
        input.addEventListener('blur', function () {
            ul.style.display = "none"
            input.classList.remove('search')
        })

    </script>
</body>

</html>